package listen.beans.factory.config;

import listen.beans.PropertyValues;

/**
 * 定义 Bean 实例信息
 */
public class BeanDefinition {
    String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;
    String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;

    private Class beanClass;

    private PropertyValues propertyValues;

    private String initMethodName;

    private String destroyMethodName;

    private String scope=SCOPE_SINGLETON;

    private boolean singleton=true;

    private boolean prototype=false;

    /**
     * 在xml注册Bean定义时，通过scope字段来判断是单例还是原型
     * @param scope
     */
    public void setScope(String scope){
        this.scope=scope;
        this.singleton=SCOPE_SINGLETON.equals(scope);
        this.prototype=SCOPE_PROTOTYPE.equals(scope);
    }

    public BeanDefinition(Class beanClass) {
        this.beanClass = beanClass;
        this.propertyValues = new PropertyValues();
    }

    public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
    }

    public Class getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class beanClass) {
        this.beanClass = beanClass;
    }

    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }

}
